06.Disk Acquisition linux dd
π― Lab Objective:
To acquire a forensic image of a hard disk using Linux system tools while dealing with challenges such as bad sectors or large image sizes.
π Personal Note:
During my work on this lab, I used an external hard drive of approximately 112 GB. It appeared empty when opened, but I noticed the free space was only around 100 GB, meaning that about 12 GB was unaccounted for!\ This sparked my curiosity, and instead of acquiring just one partition, I decided to take a full image of the entire disk for comprehensive analysis to find out what caused this missing space.\ It was a valuable and practical experience in digital forensics and highlighted the importance of full disk acquisition, especially when hidden or unclear data is suspected.
π§© Introduction: What is Disk Acquisition?
Disk Acquisition is the process of copying bit-by-bit from storage media (either a disk or partition) to obtain an exact duplicate for investigation or analysis purposes without altering the original source.
π Image vs Clone:
| Type | Description |
|---|---|
| Image | A digital file containing an exact copy of the disk, which can be easily stored and analyzed. |
| Clone | A physical copy to another disk, typically of the same size. |
β Using an image is better because it facilitates copying, verification, storage, and analysis.
ποΈ Locating the Device in the Filesystem
-
Each physical disk has a path under
/dev/such as: -
/dev/sdaβ Primary disk. -
/dev/sdbβ External disk. -
/dev/sdb1β A partition.
β οΈ Do not confuse a partition (
sdb1) with the whole disk (sdb)!\ β οΈ Be careful: if you acquire only from/dev/sdb1, you will miss any unallocated or hidden data outside the partition.
π₯οΈ Step 1: Connect the Disk and Check its Status
Once the external hard drive is connected to a Linux system, it will be in one of two states:
-
Mounted: The disk is visible in the system and attached to a folder (mount point).
-
Not Mounted: The disk is connected but not attached, and doesnβt appear in the filesystem.
To check connected disks:
lsblk
Shows device names such as
/dev/sda,/dev/sdband their sizes.
You can also use:
sudo fdisk -l
Gives more detailed info: number of sectors, size, file system type, partitions.
sudo blkid
Displays UUID, file system type, and partition labels.
π Important Note: Make sure you distinguish between sdb (entire disk) and sdb1 (a single partition). Choose based on whether you want to copy just one partition or the whole disk.
π Step 2: Analyze Disk and Partition Size
- Use this command to analyze used space:
df -h
- Compare sector counts between the disk and the partition:
sudo fdisk -lu /dev/sdb
β If the disk and partition sizes are nearly equal, you may copy only the partition. If there's a significant difference, hidden partitions may exist, and full disk acquisition is recommended.
π½ Step 3: Acquire the Image using dd
dd is a powerful Linux tool that allows bit-by-bit copying.
β Basic Syntax:
sudo dd if=/dev/sdX of=/path/image.img bs=4M status=progress
-
if=: Input source (disk or partition). -
of=: Output file path. -
bs=4M: Block size to improve performance. -
status=progress: Shows operation progress.
π Practical Example:
sudo dd if=/dev/sdb of=~/Desktop/images/ExternalHD-Image.dd bs=4M status=progress
β οΈ Step 4: Handling Bad Sectors During Copy
If you suspect bad sectors, use:
sudo dd if=/dev/sdb of=~/Desktop/images/disk_image_safe.img conv=noerror,sync
| Option | Meaning |
|---|---|
noerror |
Ignore read errors (bad sectors). |
sync |
Fills corrupted areas with zero to maintain structure. |
π Step 5: Splitting Large Images
If the image is larger than the available storage:
sudo dd if=/dev/sdb | split -b 100M - ~/Desktop/images/disk_part_
Splits the image into files like
disk_part_aa,disk_part_abβ¦
To reassemble later:
cat disk_part_* > full_image.dd
π‘οΈ Step 6: Verify Image Integrity (Hashing)
To ensure no tampering occurred:
md5sum image.dd > image.dd.md5
sha256sum image.dd > image.dd.sha256
β Comparing hashes later confirms the original image matches the analysis copy.
β Real Example:
sansforensics@as: ~/DF/HashFiles
cat MyImageExternalHash.md5
915d6457aee3439b296e1dcd35021083 Hash_ExternalHD_Image.img
----------------------------------------------------------------------------------
sansforensics@as: ~/DF/Analysis
md5sum F1-ExternalHD-Image.dd
915d6457aee3439b296e1dcd35021083 F1-ExternalHD-Image.dd
π Step 7: Mounting and Analyzing the Image
To analyze content without restoring the image to a new disk:
- Create a mount folder:
mkdir Mount_Point
- Attach image to a virtual device:
sudo losetup -fP F1-ExternalHD-Image.dd
- Confirm partition appearance:
ls /dev/loop*
# out :
/dev/loop0 /dev/loop1 /dev/loop3 /dev/loop5 /dev/loop7
/dev/loop0p1 /dev/loop2 /dev/loop4 /dev/loop6 /dev/loop-control
- Mount (for NTFS, for example):
sudo mount -t ntfs-3g /dev/loop0p1 Mount_Point/
- Verify successful mount:
ls Mount_Point/
out :
'$RECYCLE.BIN' 'System Volume Information'`
π Youβll see folders like
$RECYCLE.BINandSystem Volume Information.
π§ͺ Advanced: If Image Has a Partition Table
- Extract partitions from a
.imgfile:
kpartx -av disk_image.img
- Then mount:
mount /dev/mapper/loop0p1 /mnt/image_mount
π Forensic Best Practices
| Action | Reason |
|---|---|
| Use a Write Blocker | Prevents accidental writes to original disk. |
| Work on a copy, not original | Preserves evidence. |
| Create and document hash | Ensures integrity. |
| Log each step with timestamps | For court admissibility. |
βοΈ Clean Up After Completion
To safely unmount:
sudo umount Mount_Point
sudo losetup -d /dev/loop0
β Summary of Steps
| Step | Tool | Purpose |
|---|---|---|
| Identify devices | lsblk, fdisk -l |
Determine target disk |
| Acquire image | dd |
Create a bit-by-bit copy |
| Handle errors | conv=noerror,sync |
Skip bad sectors |
| Split image | split, cat |
Manage large image files |
| Verify integrity | md5sum, sha256sum |
Ensure data consistency |
| Analyze image | losetup, mount, kpartx |
Read content safely |
π Forensic Best Practices
| Practice | Purpose |
|---|---|
| Use Write Blocker | Prevent modification to original evidence. |
| Work on a copy | Protect digital evidence from accidental changes. |
| Document hash | Guarantees evidence integrity. |
| Log every step (Chain of Custody) | Present in court as documented proof. |